Javascript 两个按钮一个具有额外功能
我有两个不同的按钮。单击这两个选项都会运行JQuery函数“ShowCommentBox” 但是,当点击第二个按钮时,我想沿着“SHowCommentBox”加载一个额外的JQuery函数,该函数允许在屏幕上显示额外的选项Javascript 两个按钮一个具有额外功能,javascript,jquery,asp.net,html,Javascript,Jquery,Asp.net,Html,我有两个不同的按钮。单击这两个选项都会运行JQuery函数“ShowCommentBox” 但是,当点击第二个按钮时,我想沿着“SHowCommentBox”加载一个额外的JQuery函数,该函数允许在屏幕上显示额外的选项 <input id="SubmitCommentsForBOQ" type="button" value="Comments" onclick="ShowCommentBox('<%: item.ItemCode %>'')" /> ,使附加功能可见
<input id="SubmitCommentsForBOQ" type="button" value="Comments" onclick="ShowCommentBox('<%: item.ItemCode %>'')" />
,使附加功能可见…我如何才能做到这一点
谢谢你的回复
下面是原始JQuery:它加载一个对话框
function ShowCommentBox(itemIdentifier, labourOrPlant, desc) {
id = itemIdentifier;
LabouringOrPlanting = labourOrPlant;
description = desc;
Function.DisplayBox(itemIdentifier);
$("#LabourOrPlantDialog").dialog({ modal: true });
}
还有我的其他代码:
<div id="LabourOrPlantDialog" title="Comments" style="display:none;">
<table class="detailstable FadeOutOnEdit">
<tr>
<th>Item</th>
</tr>
<tr>
<td id="Item"></td>
</tr>
</table>
<br />
<textarea id="ExistingComments" type="text" runat="server" rows="7" cols="30"
maxlength="2000"> </textarea>
<input id="SubmitComment" type="button" value="Submit"
onclick="SubmitButton()" />
<br />
<div id="hiddenBox">
<input type="text" name="BoqTextBox" id="BoqTextBox" value="7.15" />
</div>
</div>
项目
最好是。您可以使用HTMLdata-
属性解决这两个问题
首先将数据嵌入HTML:
<input id="SubmitCommentsForBOQ" type="button" value="Comments"
data-item-code="<%: item.ItemCode %>" />
多个处理程序将按绑定顺序执行,因此您也可以执行以下操作:
// happens first, but only for this specific button
$("#SubmitCommentsForTwo").click(function () {
$("#hiddenBox").show();
});
// happens for all buttons
$("input[data-item-code]").click(function () {
var itemCode = $(this).data('itemCode');
ShowCommentBox(itemCode);
});
如果您有两个不同的按钮,为什么不更改第二个按钮的onclick功能呢?它们是两个独立的DOM元素,对吗?
$("#SubmitCommentsForBOQ").click(function () {
var itemCode = $(this).data('itemCode');
ShowCommentBox(itemCode);
});
$("#SubmitCommentsForTwo").click(function () {
$("#hiddenBox").show();
var itemCode = $(this).data('itemCode');
ShowCommentBox(itemCode);
});
// happens first, but only for this specific button
$("#SubmitCommentsForTwo").click(function () {
$("#hiddenBox").show();
});
// happens for all buttons
$("input[data-item-code]").click(function () {
var itemCode = $(this).data('itemCode');
ShowCommentBox(itemCode);
});