我如何获得放在< p>内的字符串或int值?使用jquery的元素? [英] How do i get the string or int value which is placed inside a <p> element using jquery?

查看:49
本文介绍了我如何获得放在< p>内的字符串或int值?使用jquery的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想获取位于

元素内的值(字符串或整数)?例如:



 <   P     id   =  AvailableSize >  选择尺寸 @item <   / P  >  





@item等于数字'23'或字符串'ten'?


我尝试了什么:



我没有尝试任何东西,因为我是jquery和javascript的新手,任何帮助将不胜感激。在此先感谢。

解决方案

根据您的设计尝试使用以下代码:

 <   p     id   =  AvailableSize > 选择大小@item <   / p  >  



 alert(


#AvailableSize)。text()。split( ' ')[ 2 ]);



虽然您将在上面的代码中获得 @item 值,但如果您使用 span 里面 p 标签li ke:

 <   p  < span class =code-attribute>   id   =  AvailableSize > 选择大小<   span     id   =   SizeCount >  @item <   / span  >  <   / p  >  



< pre lang =Javascript> alert(


#SizeCount).te XT());


Hi there, i would like to get the value (string or int) which resides inside a

Element? for example:

<P id="AvailableSize">Select Size @item</P>



Where @item equals to a number '23' or maybe a string 'ten'?

What I have tried:

didn't tried anything so far as i am new to jquery and javascript, any help would be appreciated. Thanks in advance.

解决方案

As per your design try with below code:

<p id="AvailableSize">Select Size @item</p>


alert(


("#AvailableSize").text().split(' ')[2]);


Although you will get @item value in above code, but it would be better if you use span inside p tag like:

<p id="AvailableSize">Select Size <span id="SizeCount">@item</span></p>


alert(


("#SizeCount").text());


这篇关于我如何获得放在&lt; p&gt;内的字符串或int值?使用jquery的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆