Pretty straight forward question and I have no idea how or if it can be done. I've searched the web for a while and haven't found anything. What I'm trying to figure out is if I can get the value of an ID in a html element. For example I want to get Joe
out of this <div id="Joe">
. Is there a way to do this? Any help would be greatly appreciated.
很直接的问题,我不知道如何或是否可以做到。我在网上搜索了一段时间,但没有找到任何东西。我想弄清楚的是,我是否可以在html元素中获取ID的值。例如,我想让乔离开这个
2 个解决方案
#1
You should be looking for DOM crawlers.. Symphony has a really nice one, and it's pretty straight forward. you'll find in their documentation all the possible ways of getting attributes out of elements.
你应该寻找DOM爬行器.. Symphony有一个非常好的,它非常直接。你会在他们的文档中找到从元素中获取属性的所有可能方法。
You'll need composer to install the package (it's a lot easier, but not a must)
你需要使用composer来安装软件包(它更容易,但不是必须的)
you can find the package here
你可以在这里找到包裹
best of luck.
祝你好运。
#2
You can get the value using
您可以使用获取值
$('.element').attr('id');
but for this you need to add a class something like element on div
但为此你需要在div上添加类似元素的类
#1
You should be looking for DOM crawlers.. Symphony has a really nice one, and it's pretty straight forward. you'll find in their documentation all the possible ways of getting attributes out of elements.
你应该寻找DOM爬行器.. Symphony有一个非常好的,它非常直接。你会在他们的文档中找到从元素中获取属性的所有可能方法。
You'll need composer to install the package (it's a lot easier, but not a must)
你需要使用composer来安装软件包(它更容易,但不是必须的)
you can find the package here
你可以在这里找到包裹
best of luck.
祝你好运。
#2
You can get the value using
您可以使用获取值
$('.element').attr('id');
but for this you need to add a class something like element on div
但为此你需要在div上添加类似元素的类