jQuery在点击时操纵DOM

时间:2016-02-13 16:14:22

标签: javascript jquery coffeescript

我想在点击链接时将隐藏的输入值更改为if(isset($_POST['reply_msg'])) { $date = date("Y-m-d H:i:s"); $sql = mysql_query("INSERT into pm (sent_to, sent_by, date, title, content, status) VALUES('%s','%s','%s','%s','%s','%s')" , $MSGInfo['sent_by'] , $MSGInfo['sent_to'] , $date , mysql_real_escape_string($_POST['reply_title']) , mysql_real_escape_string($_POST['reply_conent']) , 'Unread'); if (!$sql){ die('Sending failed '); } else echo 'Sent!'; } true

false

我知道有一个方法<a href="#" class="open-advanced-search">Advanced search</a> advanced_search = $('.advanced-search-block .hidden-block') advanced_search_field = $('#payment_search_advanced_search') $('.open-advanced-search').on 'click', -> if '#help needed here' $(advanced_search).show() $(advanced_search_field).attr('value', 'true') else $(advanced_search).hide() $(advanced_search_field).attr('value', 'false') return return 但这对我来说已经足够了,因为我也想更新html元素。

1 个答案:

答案 0 :(得分:1)

您不需要if ... else,您可以在一个块中同时执行show / hide和true / false开关,如下所示:

$(advanced_search).toggle()
$(advanced_search_field).attr('value', $(advanced_search).is(':visible'))

第一行打开和关闭可见性。然后第二行会读出它现在是否可见,如果是,结果是true其他false