我正在使用before函数在wordpress中添加带有jquery函数的html表单,但在html代码中单击事件不起作用
我正在使用点击功能,但可能对代理人一无所知
jQuery(document).ready(function( $ ){
$("#slider-6-layer-11").before("<div class='search-container' id='search'><form action='#' class='form-horizontal' style='display: inline-flex;'><select style='width: 350px;font-size:30px;color: #888484;font-weight: 600;' class='form-control' name='type'><option class='form-control new' value='i am'> I am a</option><option id='container' class='form-control' value='rentar'>Rentar</option><option class='form-control expand' value='buyer'>Buyer</option><option class='form-control expand' value='seller'>Seller</option></select><button id='mybutton' type='submit' style='display:inline-flex;height:50px;'><i class='fa fa-search'></i></button></form></div>");
$('.new').on('click',function () {
alert("Hello!");
});
});
不要得到classname='new'
不知道为什么
答案 0 :(得分:1)
请在change
上使用<select>
事件,因为<option>
跨浏览器不支持事件
$('#search select').on('change',function () {
if($(this).find(':selected').hasClass('new')){
alert('Hello')
}
});