在osclass的脚本上添加一条错误消息

时间:2017-04-18 04:12:18

标签: javascript html

如何在此脚本中添加错误消息:

$('input[name="s_postby"]').attr("required", false); // put the id of the input field that you whant required

<script type="text/javascript">
$('#catId').change(function(){
  if( $('#catId').val() == "28" || $('#catId').val() == "29" || 
$('#catId').val() == "30" || $('#catId').val() == "31")
    {
       $("#postby").hide();  // change Posted By with ID you give to the div
    $('input[name="s_postby"]').attr("required", false); // put the id of the input field that you whant required
    }else
    {
        $("#postby").show(); // change Posted By with ID you give to the div
    $('input[name="s_postby"]').attr("required", true); // put the id of the input field that you whant required
    }
});
</script> 

1 个答案:

答案 0 :(得分:0)

如果要调试错误消息,可以在脚本中使用console.log()函数。或者,如果您希望在弹出窗口中看到它,则可以在脚本中使用alert()函数。如果您希望用户看到错误消息,那么您可以创建一个div,并将错误消息作为其内容并隐藏/显示div。

为了动态设置错误消息,您可以使用document.getElementById函数获取DOM元素,然后使用innerText属性将DOM元素的文本设置为错误消息。请找到以下示例:

LOCAL=test1
REMOTE=test2
msg=$(comm -3 <(sort ${LOCAL}) <(sort ${REMOTE}))
echo $msg