按钮调用javascript与编程参数

本文关键字:编程 参数 javascript 调用 按钮 | 更新日期: 2023-09-27 18:05:29

我有一些代码在我的视图工作良好:

<button id="foo" onclick="myMethod('false', 'true');return false;" class="btn btn-large btn-primary pull-right" style="margin-bottom:10px;" type="button">Not Present</button>

在某些情况下,我想改变传递给myMethod的参数,但是当我尝试:

<button id="foo" onclick="myMethod('false', @Status);return false;" class="btn btn-large btn-primary pull-right" style="margin-bottom:10px;" type="button">Not Present</button>

我在错误列表中得到一个无效字符的警告,如果我运行它,那么我有一个空白而不是第二个参数。

我可以修改代码,使其具有if块:

@if{Status}
  .... Button with true parameter
else
  ....Button with false parameter

但这似乎有点离谱。那么,在javascript函数调用的参数中混合@Parameter的语法是什么?

按钮调用javascript与编程参数

请使用jquery来解决您的问题,如果它不能解决您的问题,请让我知道…

<button id="foo" class="btn btn-large btn-primary pull-right" style="margin-bottom:10px;" type="button">Not Present</button>
<script>
$(document).ready(function(){
$('#foo').click(function(){
@{
if(status)
{<text>myMethod(false,true);</text>}
else
{<text>myMethod(false,false);</text>}
}
});
});
function myMethod(var par1,var status){
//Your logic here
return false;
}
</script>