为特定的隐藏字段javascript/jquery赋值
Assign Value on a specific hidden field javascript/jquery
祝您愉快!
如何使用JavaScript或jQuery为行中的隐藏字段赋值?
这是我的js:
function removeRow(){
$('input#deleteId').val("yes");
$(this).closest('tr').hide();
return false;
};
但是上面的代码用deleteId类更改了我表上的所有隐藏字段,我的问题是如何更改单击删除按钮的特定行的隐藏字段值?我的表格结构是这样的:
<table>
<tr>
<td>itemName</td>
<td>itemPrice<input type="hidden" id="deleteId" /><td>
<td><a href="#">remove</a></td>
<tr>
</table>
通过wat,它是一个外部js文件。
非常感谢您抽出时间!
您可以在输入中使用id="deletedId"
。但是id对于页面来说应该是唯一的,所以在您的情况下使用类"标识符"可能更合适。
Js报价:http://jsfiddle.net/B9De7/
$(function(){
$('a').on('click', function(){
removeRow(this);
});
});
function removeRow(anchorElementClicked){
var row = $(anchorElementClicked).closest('tr');
row.find('input.hidden-deleted-id').val("yes");
row.hide();
//no need to return false or stop eventPropagation
}
<table>
<tr>
<td>itemName</td>
<td>itemPrice<input type="hidden" class="hidden-deleted-id" /><td>
<td><a href="#">remove</a></td>
<tr>
</table>
您的代码没有按照您的意愿执行,因为它不正确,试试这个:
<table>
<tr>
<td>itemName</td>
<td>itemPrice<td>
<td><a class='removeRow' id='element-id'>remove</a></td>
<tr>
</table>
$(".removeRow").click(function(e) {
$.post( "page.php", { id: $(this).attr("id") })
// if you want the answer from the php page, ex to tell user if the remotion succeeded or not
.done(function( data ) {
$(this).parent().parent().hide();
// for example, "data" could be yes/not
alert( "Removed: "+data );
});
e.preventDefault();
});
// PHP PAGE
<?php
//DB Connection stuff
$_POST['id'] is what you get, then you have to
echo "yes/not" depending on the esit of the query.
that echo is sent back to ajax request.
它应该*隐藏包含用户单击的元素的。e.preventDefault(),以避免重新加载页面。
编辑:现在它应该将您的输入标记值设置为"yes"并隐藏第行。为什么不在用户单击"删除"的同时使用ajax来查询数据库呢?如果你愿意,我可以给你写代码。
相关文章:
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- Javascript(jQuery)给了我奇怪的结果
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- Javascript/jQuery中的并行Ajax调用
- 我可以在Javascript/jQuery中使用一个变量作为键吗
- Javascript/Jquery/PHP加载页面-如何
- Javascript/Jquery Blob not showing Chrome PDF
- 如何使用javascript/jquery获取iframe的URL的锚点属性
- OnClick/Onhover Javascript/jquery
- 如何从javascript/jquery中的复选框中获取布尔值
- javascript/jquery将utc转换为短格式的本地时间
- 在不设置协议的情况下,使用javascript/jquery更改iframe-src
- 如何向这个javascript/jquery函数添加参数
- 用JavaScript/jQuery点击图片,选中多个方框
- 使用Javascript/JQuery获取JSON GET数据
- 从数组中删除元素的最佳方法是:javascript/jquery
- Javascript/jQuery压缩一个图像正确的评论帖子,并使用Ajax Laravel 5.2保存到控制器中
- 用DRY方式Javascript/JQuery动态替换HTML
- 类似Javascript JQuery的库
- 如何在 Javascript/jQuery 中获取一些随机下拉列表的选定值