我找不到任何关于如何隐藏按钮的文档,当它填充的字段有值时。我发现的所有参考文章都指的是如果值为空,则隐藏按钮。
如果“helpdesk_ticket_custom_field_rma_210279”已经填充了值,我需要禁用或隐藏“rmabutton”
<input type="button" id="rmabutton" onclick="RMA()" value="Generate RMA #">
<script type="text/javascript">
function RMA(){
//formatted day
var date = new Date();
var d = date.getDate();
var day = (d < 10) ? '0' + d : d;
//formatted month
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
//formatted year
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
//grab agent ID
var agent = $("helpdesk_ticket_responder_id").value;
//Isolate agent ID last 5 digits for use in RMA as agent number
var agent_short = agent.slice(5,10)
//grab ticket number and eliminate special characters
var ticket = $("ticket-display-id").innerHTML.replace(/[^a-zA-Z0-9 ]/g, "");
//parse new RMA # day-month-year-agent-ticket
var rma_number = ""+month+""+day+""+year+"-"+agent_short+"-"+ticket+"";
//replace RMA field contents with new RMA #
$("helpdesk_ticket_custom_field_rma_210279").value = rma_number;
}
</script>
答案 0 :(得分:1)
在测试值的RMA输入字段上使用keyup
处理程序,并根据它切换按钮的可见性。
$("#helpdesk_ticket_custom_field_rma_210279").keyup(function() {
$("#rmabutton").toggle(this.value == '');
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="helpdesk_ticket_custom_field_rma_210279">
<input type="button" id="rmabutton" value="Generate RMA #">
&#13;
答案 1 :(得分:0)
嗨,请查看http://jsfiddle.net/elviz/2z1nvg7y/
$("#helpdesk_ticket_custom_field_rma_210279").keyup(function(){
$("#rmabutton").hide();
});