我正在尝试更改图像的alt,我点击选择图像的类(add_answer)
注: 含有不同内多次显示出来的.add_answerdiv
jQuery(function(){ // Add Answer
jQuery(".add_answer").click(function(){
var count = $(this).attr("alt");
count++;
$('.a_type_'+count+'').show();
$(this).parents("div:first").$('.add_answer').attr("alt", count);
});
});
Run Code Online (Sandbox Code Playgroud)
这行似乎不起作用,如何add_answer通过它的父类选择此类div
$(this).parents("div:first").$('.add_answer').attr("alt", count);
Run Code Online (Sandbox Code Playgroud)
其他人有想法吗?
单击时我正在尝试降低图像alt上的值.add_answer.destroy_answer
jQuery(function(){ // Hide Answer
jQuery(".destroy_answer").click(function(){
$(this).parents("div:first").hide();
var count = $('.add_answer').attr("alt");
count--;
$('.add_answer',$(this).parent('div:first')).attr('alt',count);
});
});
Run Code Online (Sandbox Code Playgroud)
问题线:
$('.add_answer',$(this).parent('div:first')).attr('alt',count);
Run Code Online (Sandbox Code Playgroud) 我有一个功能,我目前正在使用它来显示隐藏的div.a_type
如何修改此代码,以便不是在隐藏div中淡入,我可以将新div添加到DOM
jQuery(function(){ // Add Answer
jQuery(".add_answer").click(function(){
if(count >= "4"){
alert('Only 4 Answers Allowed');
}else{
var count = $(this).attr("alt");
count++;
$(this).parents('div:first').find('.a_type_'+count+'').fadeIn();
$(this).attr("alt", count);
}
});
});
好的,既然我已经解决了这个问题,我还有一个问题,
我有另一个函数,如果单击一个按钮,将删除插入的div.现在它没有工作,额外的div没有加载到页面加载的dom.我如何触发功能现在删除这些?
jQuery(function(){//隐藏答案
jQuery(".destroy_answer").click(function(){
$(this).parents("div:first").fadeOut(function (){ $(this).remove() });
var count = $(this).parents('div:first').parents('div:first').find('.add_answer').attr("alt");
count--;
$(this).parents('div:first').parents('div:first').find('.add_answer').attr("alt", count);
});
Run Code Online (Sandbox Code Playgroud)
});
循环浏览页面上所有单选按钮的最佳方法是什么,如果其中一个单元格未针对特定问题取消选中,则提醒用户?
注意:一页上有多个问题.
<li>
<fieldset>
<h3>What music do you listen to?</h3>
<ul class="answerList">
<li>
<input type="radio" id="choice_22" name="answer8" value="1" class=""/>
<label for="choice_22" class="">Heavy Metal </label>
</li>
<li>
<input type="radio" id="choice_23" name="answer8" value="2" class=""/>
<label for="choice_23" class="">Pop music</label>
</li>
<li>
<input type="radio" id="choice_24" name="answer8" value="3" class=""/>
<label for="choice_24" class="">Oh, a mix of stuff </label>
</li>
</ul>
</fieldset>
</li>
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有jquery的id改变图像的边框颜色(照片['id']从前一个函数传入)照片的ID是'photo239839'的形式
$('#photo'+photo['id']+'').click(function(){
$('#photo'+photo['id']+'').css('border-color','#777');
});
Run Code Online (Sandbox Code Playgroud)
当我尝试使用它的类使用相同的代码时它可以工作,但我不能使用这个方法,因为在同一页面上有多个图像具有相同的类
$('img.flickr_photo').click(function() {
$("this.flickr_photo").css('border-color','#777');
});
Run Code Online (Sandbox Code Playgroud) 我正在使用jquery.flickr-1.0.js在我的应用程序中搜索flickr中的图像.我面临的问题是,有时flickr响应结果需要几秒钟,我想加载一个旋转的gif代替我的搜索按钮'btnRefresh',直到返回结果.我怎么能做到这一点?
jQuery(function(){
jQuery(".btnRefresh").livequery('click', function(){
var number = $(this).attr("id");
$('#gallery_flickr_'+number+'').show();
jQuery('#gallery_flickr_'+number+'').html("").flickr({
api_key: "XXXXXXXXXXXXXXXXXXXX",
per_page: 18,
search_text: $('input#flickr_search_'+number+'').val(),
id: $(this).attr("id")
});
});
});
Run Code Online (Sandbox Code Playgroud)