在jquery对话框中单击按钮获取标签的值
我在jquery对话框中显示从webservice客户端返回的数据,动态地以表的形式显示,每一行还具有一个按钮,用于选择行的值并将其返回主窗口在jquery对话框中单击按钮获取标签的值,jquery,row,Jquery,Row,我在jquery对话框中显示从webservice客户端返回的数据,动态地以表的形式显示,每一行还具有一个按钮,用于选择行的值并将其返回主窗口 $("<div/>") .attr({ "class": "line dataRow ProductSearchResultRow", "custom:id": vProdLines[i].id, "custom:title": vProdLines[i].title,
$("<div/>")
.attr({ "class": "line dataRow ProductSearchResultRow",
"custom:id": vProdLines[i].id,
"custom:title": vProdLines[i].title,
"custom:composer": vProdLines[i].composer,
"custom:performer": vProdLines[i].performer,
"custom:rec": vProdLines[i].rec
})
.append($("<div/>").attr({ "class": "unit size3p" }).html($("<label/>").html(vProdLines[i].rec)))
.append($("<div/>").attr({ "class": "unit size1of5" }).html($("<label/>").html(vProdLines[i].title)))
.append($("<div/>").attr({ "class": "unit size1of8" }).html($("<label/>").html(vProdLines[i].composer)))
.append($("<div/>").attr({ "class": "unit size1of8" }).html($("<label/>").html(vProdLines[i].arranger)))
.append($("<div/>").attr({ "class": "unit size1of8" }).html($("<label/>").html(vProdLines[i].performer)))
.append($("<div/>").attr({ "class": "unit size1of10" }).html($("<label/>").html(vProdLines[i].publisher)))
.append($("<div/>").attr({ "class": "unit size8p" }).html($("<label/>").html(vProdLines[i].label)))
.append($("<div/>").attr({ "class": "unit size8p" }).html($("<label/>").html(vProdLines[i].catNo)))
.append($("<div/>").attr({ "class": "unit size5p" })
.append($("<div/>").attr({ "class": "unit size1of10" })
.append($("<input/>")
.attr({ "type": "button" })
.val("Select")
.click(function () {
$("div.ProdSearchResultRow").removeClass("SelectedRow");
$(this).addClass("SelectedRow");
$("#newProdTitleId").val($(this).attr("custom:id"));
$("input#txtProdSheetSelectedMusicTitle").val($(this).attr("custom:title"));
$("input#txtProdSheetSelectedComposer").val($(this).attr("custom:composer"));
$("input#txtProdSheetSelectedPerformer").val($(this).attr("custom:performer"));
$("#tdProdNewRec").children("select").val($(this).attr("custom:rec"));
ClosePopupBox("modalProdSearch");
$(“”)
.attr({“类”:“行数据行ProductSearchResultRow”,
“custom:id”:vProdLines[i].id,
“自定义:标题”:vProdLines[i]。标题,
“自定义:编写器”:vProdLines[i]。编写器,
“自定义:执行者”:vProdLines[i]。执行者,
“自定义:rec”:vProdLines[i].rec
})
.append($(“”).attr({“class”:“unit size3p”}).html($(“”).html(vProdLines[i].rec)))
.append($(“”).attr({“class”:“unitsize1of5”}).html($(“”).html(vProdLines[i].title)))
.append($(“”).attr({“class”:“unitsize1of8”}).html($(“”).html(vProdLines[i].composer)))
.append($(“”).attr({“class”:“unitsize1of8”}).html($(“”).html(vProdLines[i].arranger)))
.append($(“”).attr({“class”:“unit size1of8”}).html($(“”).html(vProdLines[i].performer)))
.append($(“”).attr({“class”:“unit size1of10”}).html($(“”).html(vProdLines[i].publisher)))
.append($(“”).attr({“class”:“unit size8p”}).html($(“”).html(vProdLines[i].label)))
.append($(“”).attr({“class”:“unit size8p”}).html($(“”).html(vProdLines[i].catNo)))
.append($(“”).attr({“类”:“单位大小5p”})
.append($(“”).attr({“类”:“单位大小10”})
.append($(“”)
.attr({“类型”:“按钮”})
.val(“选择”)
。单击(函数(){
$(“div.ProdSearchResultRow”).removeClass(“SelectedRow”);
$(this.addClass(“SelectedRow”);
$(“#newProdTitleId”).val($(this.attr(“custom:id”));
$($(输入#txtProdSheetSelectedMusicTitle”).val($(this.attr(“自定义:标题”));
$(“input#txtProdSheetSelectedComposer”).val($(this.attr(“custom:composer”));
$($(输入#txtProdSheetSelectedPerformer”).val($(this.attr(“自定义:performer”));
$(“#tdProdNewRec”).children(“select”).val($(this.attr(“custom:rec”));
ClosePopuBox(“modalProdSearch”);
一切都显示得很好,对话框也关闭了,但我无法获得
每个div元素内标签中的行
我知道使用“this”实际上会指向button而不是main div,但在单击button时无法获取行的值
呈现的页面html如下所示:
<div class="line dataRow MusicSearchResultRow" id="myid_1452708" id="myid_1452708"
custom:title="TEST" custom:id="1452708" custom:composer="AL" custom:performer="AL"
custom:rec="C">
<div class="unit size3p">
<label>
C</label></div>
<div class="unit size1of5">
<label>
TEST</label></div>
<div class="unit size1of8">
<label>
AL</label></div>
<div class="unit size1of8">
<label>
AL</label></div>
<div class="unit size1of8">
<label>
AL</label></div>
<div class="unit size1of10">
<label>
</label>
</div>
<div class="unit size8p">
<label>
</label>
</div>
<div class="unit size8p">
<label>
1234</label></div>
<div class="unit size5p">
<input type="button" value="info"></div>
<div class="unit size1of10">
<input type="button" value="Select"></div>
</div>
C
试验
艾尔
艾尔
艾尔
1234
您是否尝试过为您的div提供id并从中获取属性
$("<div/>")
.attr({ "id": "myid",
"class": "line dataRow ProductSearchResultRow", //rest of it
与
id需要是qunique,所以你可能需要做一些类似的事情
$("<div/>")
.attr({ "id": "myid_" + vProdLines[i].id,
要隔离实例,
将单击此
元素,然后您可以使用最近的()
获取行实例
拥有行实例后,可以在行内使用find()
访问该行的其他元素
$("<input/>")
.attr({
"type": "button"
})
.val("Select")
.click(function () {
var $buttonClicked = $(this),
$closestRow = $buttonClicked.closest('.ProdSearchResultRow');
var $anotherElementInThisRow = $closestRow.find('.someClass');
});
$(“”)
艾特先生({
“类型”:“按钮”
})
.val(“选择”)
。单击(函数(){
变量$buttonClicked=$(此),
$closestRow=$buttonClicked.closest('.ProdSearchResultRow');
var$anotherelementhislow=$closestRow.find('.someClass');
});
了解。动态代码已添加到此div“divProdSearchBox”谢谢,尝试了此操作,但出现以下错误“JavaScript运行时错误:无法获取未定义或空引用的属性“id”在button click中,您可以添加这些行并查看得到的结果:console.log(“prodlineid:+vProdLines[i].id”);console.log(“div:+$”(“#myid_u“+vProdLines[i].id);抱歉,请在$(“”)之前尝试此操作。attr add:var divId=vProdLines[i].id;然后将id attr添加为$(“{”id:“myid”+divId),最后在button click中单击do$(“#myid”+divId).attr”(尝试此操作。在“单击按钮”中,我添加了一个警报以检查值,它始终返回最后一行属性的值。我调试并发现它在每个循环中都可以添加值,但当我在任何一行中单击“选择”按钮时,它返回最后一行值。我们将对此进行排序:)忘记id,将类添加到顶部div,即$(“”).attr({“class”:“topDivClass”,然后在您的按钮中单击use$(this).closest(“.topDivClass”).attr(
$("<div/>")
.attr({ "id": "myid_" + vProdLines[i].id,
$("#myid_" + vProdLines[i].id).attr(
$("<input/>")
.attr({
"type": "button"
})
.val("Select")
.click(function () {
var $buttonClicked = $(this),
$closestRow = $buttonClicked.closest('.ProdSearchResultRow');
var $anotherElementInThisRow = $closestRow.find('.someClass');
});