I have a form that looks like this:
<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"
}
});
}
}
这个不可能吗?