我想用我自己的属性选择和更改一个div让我说myAttribute ="1235"
我试试这个
<font myAttribute="1235">Change me !</font>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
var myAttribute = 1235;
$("[myAttribute='+myAttribute+']").html('is working');
$("[myAttribute='+myAttribute']").html('is working');
$("[myAttribute=''+myAttribute]").html('is working');
</script>
Run Code Online (Sandbox Code Playgroud)
但他们不工作!如果将代码更改为
$("[myAttribute='1235']").html('is working');
Run Code Online (Sandbox Code Playgroud)
everthing还可以,但我想使用变量
我很绝望 - 我看不出我做错了什么.我尝试替换所有出现的'8969',但我总是得到原始字符串(无论tmp是字符串还是int).也许已经太晚了,也许我是瞎了,......
var tmp = "8969";
alert("8969_8969".replace(/tmp/g, "99"));
Run Code Online (Sandbox Code Playgroud)
有人可以帮我吗?
我正在使用Galleria Fullscreen主题,不允许通过jQuery保存为图像(禁用右键单击).这段代码:
$('img').live('contextmenu', function(e){
return false;
});
Run Code Online (Sandbox Code Playgroud)
此代码适用于Firefox,Safari和Chrome Mac.我在Windows上测试过,不允许右键单击.但是当按下Windows键时,获取另存为图像.这是关键:
如何禁用此密钥?
例如:有一个页面列出了一些带颜色的项目.有些被列为Nav,有些被列为海军.
$('.ProductDetails a').each(function() {
var text = $(this).text();
$(this).text(text.replace("Nav", "Navy"));
});
Run Code Online (Sandbox Code Playgroud)
将导致所有'导航'改为海军 - 太棒了!
但它也将导致'海军'改为海军.(即它将海军中的'nav'替换为海军,并在'nav'被替换后留下'y')
有没有办法使用上面的技术来阻止这种情况,或者我必须更改脚本以解决这些双重问题.
我目前的解决方案是在Nav之后添加一个空格 $(this).text(text.replace("Nav ", "Navy"));
但这并不理想,因为有些物品可能有一个/后面没有空间.
我有一个jquery点击事件设置:
$(".clickhere").click(function(){
...
});
Run Code Online (Sandbox Code Playgroud)
我也有一个id为的跨度spanval
.
<span id="spanval">1</span>
Run Code Online (Sandbox Code Playgroud)
最后我有一个表格input
...
<input id="spanvalue" name="spanvalue" value="whatever_the_value_of_the_span_is" />
Run Code Online (Sandbox Code Playgroud)
所以,我需要做的是以下内容:
如果clickhere
单击了类,则获取文本span
并将其放入spanvalue
值中.
我有一个具有title属性的div:
<div id="video" title="<?php echo $row_rs_dealItem['video']; ?>">
Run Code Online (Sandbox Code Playgroud)
基本上如果mysql的返回值为空,那么我想添加一个类.我有以下脚本:
$(document).ready(function(e) {
$('#video[title*=""]').addClass('invisible');
});
Run Code Online (Sandbox Code Playgroud)
这似乎很容易,所以不知道我做错了什么.多谢你们
如何将文本输出到父<div>
级<span>
?我究竟做错了什么?如果有比使用 span 和 更好的解决方案.parent()
,请告诉我。
HTML:
<div>
<span></span> <!--the span where i want to output "troll" and "dwarf"-->
<a href="#" class="heroes" alt="troll">Icon</a>
<a href="#" class="heroes" alt="dwarf">Icon</a>
</div>
<div>
<span></span <!--the span where i want to output "witch"-->
><a href="#" class="heroes" alt="witch">Icon</a>
</div>
<div>
<span></span> <!--etc...-->
<a href="#" class="heroes" alt="barbarian">Icon</a>
</div>
<div>
<span></span>
<a href="#" class="heroes" alt="necromancer">Icon</a>
</div>
Run Code Online (Sandbox Code Playgroud)
JS:
$('.heroes').hover(function() {
var hero = $(this).attr('alt');
$(this).parent('span').text(hero);
}, function() {
$(this).parent('span').text("");
});
Run Code Online (Sandbox Code Playgroud)
谢谢
简单的问题,因为jQuery .live()的1.7版本已经被弃用,而不是.on(); 但.on()似乎不适用于通过JavaScript呈现并加载到DOM中的元素.所以我的问题是,应该仍然使用.live()或.on()如何捕获这些新生成的元素?
举个例子,这是我的代码:
$("#listitem").append("<li id='removeitem'>" +
formdata + ' <a href="#">Remove</a></li>');
Run Code Online (Sandbox Code Playgroud)
当我尝试通过.on()操作这个元素时 - 结果什么都没有,而.live()能够抓住这个元素.
$("#removeitem").live("click", function(event) { alert($(this).text()); });
Run Code Online (Sandbox Code Playgroud) 我需要在jquery或javascript中创建全局二维数组
我的功能是这样的
<script>
var globalArray[0] = new Array();
function createArray(){
alert(globalArray[0]);
}
</script>
<div><input type='button' value='save' onclick='createArray();'> </div>
Run Code Online (Sandbox Code Playgroud)
点击该按钮我收到此错误 "globalArray[0] is undefined"
如何创建全局动态多维数组.
当'product-input'的值发生变化时,我希望'product-total'更新.我有活动,但我似乎无法提及'product-total'.
这是HTML:
<div class='product'>
<h2>Photo Prints up to 5” x 7”</h2>
<div class='product-total'></div>
<div class='choices'>
<input type='text' class='raw standard product-input' />
</div> <!-- END Choices -->
Standard: <input type='radio' class='quality standard' value='standard' />
Full: <input type='radio' class='quality full' value='full' />
</div> <!-- END Product -->
Run Code Online (Sandbox Code Playgroud)
和jQuery:
jQuery('input.product-input').change(function() {
jQuery('div.product-total', jQuery(this).parent('div.product')).html(total);
});
Run Code Online (Sandbox Code Playgroud)