使用函数数据作为html id Jquery [英] Use function data as html id Jquery

查看:117
本文介绍了使用函数数据作为html id Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用函数数据作为id,尝试了很多但没有任何效果,我应该怎么做这里是我的代码,提前谢谢

I want to use the function data as id, tried alot but nothing worked, how should i do it here is my code, thanks in advance

function SLIDE_HIDE(SLIDEID)
{
    $("#($SLIDEID).val()").prop('value', 'hide');
}


推荐答案

您需要连接:

$("#" + SLIDEID)

这意味着如果 SLIDEID 参数是字符串test那就像是说 $(#test)

Which means that if the SLIDEID argument is, say, the string "test" then it will be like saying $("#test").

你试图选择一个元素的id等于字符串中之后的所有文本,即具有 id =($ SLIDEID).val )

You were trying to select an element with an id equal to all of the text in the string after #, i.e., an element with id="($SLIDEID).val()".

如果您试图隐藏 SLIDEID 参数然后执行此操作:

If you are trying to hide the element that has the id in the SLIDEID argument then do this:

$("#" + SLIDEID).hide();

如果你想改变那个元素的值那么(假设它是一个像输入一样的表单元素):

If you want to change that element's value then (assuming it is a form element like an input):

$("#" + SLIDEID).val('hide');

您展示的代码类似于您尝试从元素中检索值在 SLIDEID 中指定的id,然后使用该值作为id来查找另一个元素,并将该元素的值设置为字符串'hide' code>。这对我来说没有意义,但是如果你想做的话:

The code you showed sort of looks like you're trying to retrieve the value from an element with the id specified in SLIDEID and then use that value as the id to look up another element and set that other element's value to the string 'hide'. That doesn't really make sense to me, but if it's what you want to do:

$("#" + $("#" + SLIDEID).val()).prop('value', 'hide');

这篇关于使用函数数据作为html id Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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