我正在创建一个使用HTML的网页(后来的CSS,当内容和脚本启动并运行时),JavaScript和AJAX使用其REST API来管理TShock服务器(针对游戏Terraria)。 p>
我希望该页面支持大多数(如果不是全部)REST API端点(可用列表here)。
我目前在/v2/users/update端点方面存在问题。我想创建一个表单(不使用<form>
标签,我不希望主席到键盘界面搞砸'enter'键。)
端点的说明称可选字段为password
和group
。不提供至少一个将无法更新用户。
为了确保提供一个或两个,我想使用单选按钮而不是复选框(再次因为椅子到键盘的界面)。
每个单选按钮都应该启用正确的输入字段,除非他们不这样做。 Chrome的控制台不报告任何内容,以及Firefox和IE的报告。
有人有替代解决方案吗?当然,我本可以犯错。
我宁愿避免根据用户的选择更改div
的{{1}}。
JS代码(使用jQuery的代码示例):
innerHTML
HTML code:
function PassInputOnly(){
$.("#PwdField").prop("disabled", false); // Using document.getElementById("FieldId").disabled
$.("#GrpField").prop("disabled", true); // doesn't work either.
}
function GrpInputOnly(){
$.("#PwdField").prop("disabled", true);
$.("#GrpField").prop("disabled", false);
}
function BothInputs(){
$.("#PwdField").prop("disabled", false);
$.("#GrpField").prop("disabled", false);
}
注意:它与this question类似,但我想使用<input type="text" id="UpdUser" placeholder="Username">
<p>What will get updated ?</p>
<input type="radio" name="WhatGetsUpdated" onclick="BothInputs()" checked>Password and Group<br>
<input type="radio" name="WhatGetsUpdated" onclick="PassInputOnly()">Password<br>
<input type="radio" name="WhatGetsUpdated" onclick="GrpInputOnly()">Group<br>
<input type="text" id="PwdField" placeholder="New password">
<input type="text" id="GrpField" placeholder="New group">
个事件,而不是值。
答案 0 :(得分:1)
删除&#34;。&#34;在$ ie之后
$.("#PwdField") ==> $("#PwdField")
检查出来:
function PassInputOnly(){
$("#PwdField").prop("disabled", false); // Using document.getElementById("FieldId").disabled
$("#GrpField").prop("disabled", true); // doesn't work either.
}
function GrpInputOnly(){
$("#PwdField").prop("disabled", true);
$("#GrpField").prop("disabled", false);
}
function BothInputs(){
$("#PwdField").prop("disabled", false);
$("#GrpField").prop("disabled", false);
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<input type="text" id="UpdUser" placeholder="Username">
<p>What will get updated ?</p>
<input type="radio" name="WhatGetsUpdated" onclick="BothInputs()" checked>Password and Group<br>
<input type="radio" name="WhatGetsUpdated" onclick="javascript:PassInputOnly()">Password<br>
<input type="radio" name="WhatGetsUpdated" onclick="GrpInputOnly()">Group<br>
<input type="text" id="PwdField" placeholder="New password">
<input type="text" id="GrpField" placeholder="New group">
&#13;