这段代码没有按预期工作,我做错了什么?
$(document).ready(function(){
$("a.hide-para").click(function(){
$('p').hide();
$(this).html('Show Paragraphs').removeClass('hide-para').addClass('show-para');
});
$("a.show-para").click(function(){
$('p').show();
$(this).html('Hide Paragraphs').removeClass('show-para').addClass('hide-para');
});
});
Run Code Online (Sandbox Code Playgroud) 我有这个jQuery AJAX代码,当请求成功时,它会这样做:
success: function(msg)
{
$('.login-msg').css('color', 'green');
$('.login-msg').hide().html(msg).fadeIn('slow');
$('#user-tools').hide().html('<span class="user-credits"><a href="javascript:void(0);" class="logout-btn">Logout</a></span>').fadeIn('slow');
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法点击logout-btn具有jQuery点击功能的类的链接,该类将注销用户,但是当我刷新页面时,它仍然具有以下HTML:
<span class="user-credits"><a href="javascript:void(0);" class="logout-btn">Logout</a></span>
Run Code Online (Sandbox Code Playgroud)
但是为什么我不能点击它来完成这里完成的点击功能:
$('.logout-btn').click(function(){
$.ajax({
url: 'include/logout.php',
cache: false,
success: function(msg)
{
$('.logout-btn').html('<p><img src="img/loading.gif" style="vertical-align: bottom;" /> Refreshing...</p>');
setTimeout(function()
{
window.location.reload();
}, 1000);
},
error: function()
{
$('.logout-btn').css('color', 'red');
$('.logout-btn').hide().html('Error trying to log out, try again later').fadeIn('slow');
}
});
});
Run Code Online (Sandbox Code Playgroud)
干杯.
我有以下HTML和Javascript代码.我正在尝试建立一个搜索建议系统.当用户在输入框'site_search'中键入并插入时,使用ajax动态检索无序列表'search_suggest'中的列表项.
<form name="search_site_form" method="get" action="search.php">
<input id="site_search" name="q" class="search_input input" autocomplete="off" value="Search the site" type="text"/>
<ul id="search_suggest">
</ul>
<input value=" " type="submit" class="search_submit"/>
<script type="text/javascript">
<!--
$("ul#search_suggest>li").click(function(){
alert('123');
});
//-->
</script>
</form>
Run Code Online (Sandbox Code Playgroud)
但是,单击search_suggest中的列表项不会触发单击功能.知道为什么吗?
我试图在每个单击上使字体大小更大,但它只做一次这里是我的代码.
<a href="5">add</a>
<script type="text/javascript">
$('a').live('click', function(e){
e.preventDefault();
var link = $(this).attr('href');
var num = link+20;
var font = {color:"#993300", fontSize:num+"px"};
$("p").css(font);
return false;
});
</script>
Run Code Online (Sandbox Code Playgroud)
任何帮助???
我想知道为什么这个例子在Chrome 10中有效,但在Fx 3.6中不起作用?IFAIK,确切地输入type ="file"点击不起作用...
谁能解释一下,为什么?
我有一个从MySQL数据库中获取的JSON生成数据列表.我现在要做的是,当点击列表中的任何项目时,它将被添加到我的表单的隐藏输入中,但问题是,如果我这样做:
$(".buttonZvrst").click(function(){
alert("this is a test");
});
Run Code Online (Sandbox Code Playgroud)
什么都不会发生.如果我选择不在JSON生成列表中的任何其他元素,它将起作用.它不起作用,因为它是在以后产生的吗?我需要帮助!这是我的getZvrsti函数,其中JSON是.
function getZvrsti(id) {
// Save the request to our requests object
request[id] = $.getJSON('test.php?parent='+id, function(data) {
var html = "";
$.each(data, function(id, name) {
if(name['id'] in izbrani){
if(izbrani[name['id']] == true){
html += '<li id="drugaZvrst" class="izbran"><a class="buttonZvrst" href="#" id="'+name['id']+'">'+name['name']+'</a></li>';
}
else{
html += '<li id="drugaZvrst"><a class="buttonZvrst" href="#" id="'+name['id']+'">'+name['name']+'</a></li>';
}
}
else
{
izbrani[name['id']] = false
html += '<li id="drugaZvrst"><a class="buttonZvrst" href="#" id="'+name['id']+'">'+name['name']+'</a></li>';
}
});
// Append the list items and then fade in …Run Code Online (Sandbox Code Playgroud) 我已经完成了以下代码结构,addClass item_box_popup并且removeClass item_box点击了item_box div.
<div class="item_box"> <!--This is the small div which when clicked changes to the item_box_popup div-->
<div class="name">...</div>
<div class="detail">...</div>
</div>
<div class="item_box_popup"> <!--This div expands to show the detail and the children in it has a click event-->
<div class="name">...</div>
<div class="detail">...</div>
</div>
Run Code Online (Sandbox Code Playgroud)
其中item_box div有一个click事件,而不是孩子.工作是要改变到div item_box_pop div通过addClass和removeClass点击时.
在item_box_popup没有click事件,但孩子已定义click事件.我们已经习惯delegate定义click事件.item_box_popup .name等.
问题是当我们点击item_box div定义的click事件时.item_box_popup .name也会被触发.这可能是由于click for上定义的更改类所致 …
我无法使用1.7获取新的.on点击工作.
对于动态创建的链接(例如通过单击"创建"按钮生成的链接),这些链接需要与DOM中的静态链接相同的单击功能.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
<script type="text/javascript">
function createDivs(){
content = '<div class="tile-button"><a class="tile-action" href="#" rel="1234" alt="Open">Dynamic Link</a></div>';
$(content).appendTo("#dynamicArea");
$('.tile-action').bind('click',function(){});
}
$(document).ready(function(){
$('#createButton').on("click", createDivs);
$('#destroyButton').on("click", function(event){
$("#dynamicArea").html("");
});
$('.tile-action').on("click", function(event){
var linkalt = $(this).attr("alt");
var linkrel = $(this).attr("rel");
alert(linkalt + " " + linkrel);
return false;
});
});
</script>
</head>
<body>
<button id="createButton">CREATE</button> <button id="destroyButton">Destroy :(</button>
<div id="dynamicArea"></div>
<br>
<a class="tile-action" href="#" rel="1234" alt="Open">Link</a><!-- works -->
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在此问题的简化示例中,单击"创建"按钮时,将显示动态链接.当您单击没有任何反应时,这些动态链接不像静态链接那样调用警报.
我有一个页面,允许用户"轻推"某人做某事
我有以下HTML(它可以出现很多次,但我现在将显示两个)
<div class="nudgeHolder641">
<a id="nudge" data-wl_id="641" data-nudge_for="415" data-nudge_from="63" href="#">Nudge</a>
</div>
<div class="nudgeHolder1172">
<a id="nudge" data-wl_id="1172" data-nudge_for="415" data-nudge_from="63" href="#">Nudge</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我有以下代码来操作点击:
$(document).ready(function(){
$("#nudge").click(function() {
var nudge_from = $( '#nudge' ).data( 'nudge_from' );
var nudge_for = $( '#nudge' ).data( 'nudge_for' );
var wl_id = $( '#nudge' ).data( 'wl_id' );
var dataString = 'nudge_from='+ nudge_from + '&nudge_for=' + nudge_for + '&wl_id=' + wl_id;
$.ajax({
type: "POST",
url: "/pages/includes/ajax/nudge.php",
data: dataString,
success: function() {
$('.nudgeHolder'+wl_id).html("<h3>Fantastic!</h3>")
.append("<p>Nudge Sent!</p>")
.hide()
.fadeIn(1500, function() {
//$('#message').append("<img id='checkmark' …Run Code Online (Sandbox Code Playgroud) 我在表格上有两个按钮.按钮和表单都是动态创建的:
container.html(........
........
<input type='button' value='Send' id='btSend' />"+
" <input type='button' value='Save' id='btSave' />"+
................
...............)
Run Code Online (Sandbox Code Playgroud)
这里有两个函数应该收集击键:
$("#btSend").click(function(){
..........
............
}
$("#btSave").click(function(){
..........
............
}
Run Code Online (Sandbox Code Playgroud)