<input type="checkbox" name="checkBoxes" onclick="Utility('<%# Eval("id") %>');" />
onclick运行JS
<script type="text/javascript" language="javascript">
var SelectedUtilityId = -1;
var UtilityCompanyId = -1;
function Utility(id) {
SelectedUtilityId = id;
UtilityCompanyId = UtilityCompanyId;
WorkItemMgr.DisplayLabelIfTrue(SelectedUtilityId, UtilityCompanyId);
}
Eval(“id”)绑定到Id,但我也想绑定到UtilityCompanyId,因为我想将该值传递给JS ......这是怎么做到的?
由于
答案 0 :(得分:2)
只需更改功能并调用它即可传递第二个值。如,
<input type="checkbox" name="checkBoxes" onclick="Utility('<%# Eval("id") %>', '<%# someOtherValueHere %>');" />
和
function Utility(id, otherId) {
SelectedUtilityId = id;
UtilityCompanyId = otherId;
WorkItemMgr.DisplayLabelIfTrue(SelectedUtilityId, UtilityCompanyId);
}
答案 1 :(得分:2)
像这样:
<input type="checkbox" name="checkBoxes" onclick="Utility('<%# Eval("id") %>','<%# Eval("UtilityCompanyId") %>');" />
一般情况:
onclick="Utility('<%# Eval("val1") %>','<%# Eval("val2") %>','<%# Eval("val3") %>');" etc
答案 2 :(得分:1)
试试这个
<input type="checkbox" name="checkBoxes" onclick="Utility('<%# Eval("id") %>',"-1");" />
答案 3 :(得分:1)
那么只需在函数中添加额外的参数并将其传递给onclick?
<input type="checkbox" name="checkBoxes" onclick="Utility(<%# Eval("id") %>,<%# Eval("other_thing") %>);" />
和
function Utility(id, other_thing) {
SelectedUtilityId = id;
UtilityCompanyId = other_thing;
WorkItemMgr.DisplayLabelIfTrue(SelectedUtilityId, UtilityCompanyId);
}