I m 试图将1(一)从价值中分离出来。 我设法这样做:
$( .notis ).text(parseInt($(".notis").text()) - 1);
问题在于:<代码><a> 。
<a href="#" class="notis"><img src="/images/icons/picture.png">3</a>
因此,上面的分类将从价值中减去1(一个),但也消除形象! 我怎么能够这样做?
I m 试图将1(一)从价值中分离出来。 我设法这样做:
$( .notis ).text(parseInt($(".notis").text()) - 1);
问题在于:<代码><a> 。
<a href="#" class="notis"><img src="/images/icons/picture.png">3</a>
因此,上面的分类将从价值中减去1(一个),但也消除形象! 我怎么能够这样做?
You can store the image in a temporary variable, then add it to the node using the prepend
method:
$( .notis ).each(function() {
var $this = $(this); // <-- Reference to current elem
var $img = $this.find( img ); // <-- Reference to <img>
$this.text(parseInt($this.text(), 10) - 1); // <-- Your logic
$this.prepend($img); // <-- Add image again.
});
附加说明:
parseInt( ... , 10)
instead of parseInt( ... )
. Numbers prefixed by a zero will be treated inconsistently across browsers. By specifygin the radix of 10, the number will be parsed correctly.$( .notis )
selects all elements with class notis
. When you re using $( notis ).text($( notis ).text()-1)
, all elements with class notis
will contain the value of the first .notis
element (because $( .notis ).text()
returns the value of the first .notis
). That s why I used .each
in my code.$(this)
more than once, it s worth storing the variable $(this)
in a temporary variable, for improved efficiency.也许可以找到更好的解决办法,但是,在你修改案文之后,你可以挽救儿童联系内容,重新引导他们:
$( .notis ).each(function (index, element) {
var $children = $(this).children();
$(this).text(parseInt($(this).text()) - 1).prepend($children);
});
http://jsfiddle.net/epuxy/“rel=“nofollow” http://jsfiddle.net/epuxy/。 (在你点击该链接时,见上下层变化的数字)
I d suggest to wrap up the number in a <span>
and replace its content.
在干燥的或跨过的(旧的)班级中打3,并从那里取。
最好的解决办法是围绕您的号码安装span
。 这导致业绩最佳。
www.un.org/Depts/DGACM/index_spanish.htm Html
<a href="#" class="notis"><img src="/images/icons/picture.png"><span>3</span></a>
jQuery
$( .notis > span ).text(parseInt($(".notis").text()) - 1);
I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....
I have a div <div id="masterdiv"> which has several child <div>s. Example: <div id="masterdiv"> <div id="childdiv1" /> <div id="childdiv2" /> <div id="...
I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...
<form><input type="file" name="first" onchange="jsFunction(2);"> <input type="file" name="second" onchange="jsFunction(3);"</form> Possible to pass just numbers to the js ...
So I ve got a menu with a hover/selected state and it loads fine in IE6/IE7. However when I scroll down the page and put the element outside of the viewport and then back in I get a broken image! I ...
I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!