我有一个看起来像这样的表格:
<form name="armdisarmform" action="/cameras" method="POST">
<input type='hidden' name='armdisarmvalue' value="ENABLED"/>
<button class="armdisarm" name="armdisarmbutton" onClick='changeicon(this, "Disarm")'>Disarm</button>
</form>
这些值是从服务器填充的:
<form name="armdisarmform" action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?>" method="POST">
<input type='hidden' name='armdisarmvalue' value="<?php echo $userstatus; ?>"/>
<button class="armdisarm" name="armdisarmbutton" onClick='changeicon(this, "<?php echo $armdisarm; ?>")'><?php echo $armdisarm; ?></button>
</form>
本质上,我有一个按钮,可以根据服务器记录或当有人单击它时将其名称更改为“Arm”或“Disarm”。我想从 jquery 按钮添加解锁/锁定图标。所以这有效:
$(function() {
$( ".armdisarm" ).button({
icons: {
primary: "ui-icon-locked"
}
});
});
但是,当我通过一个希望更改图标的函数时,它不起作用:
var changeicon = function(t, armdisarm)
{
if (armdisarm == "Disarm")
{
$( ".armdisarm" ).button({
icons: {
primary: "ui-icon-unlocked"
}
});
}
else
{
$( ".armdisarm" ).button({
icons: {
primary: "ui-icon-locked"
}
});
}
}
这不可能吗?