English 中文(简体)
穿过参数
原标题:passing parameters to jquery function
<script>
  $(document).ready(function () {
    $("#pid1").click(function () {
        $(this).hide(SpeedEnteredByUser);
    });
});
</script>

<body>
<p id = "pid1">This is paragraph</p>
</body>

I want to call jquery hide function when paragraph is clicked. But I want to pass the speed(i.e. slow/fast) which is entered by the user. How it can be achieved ? Here SpeedEnteredByUser is the value entered by the user(using some form) and I want to pass this value to hide function.

最佳回答

Use .val() jQuery method to get the value of a text input (which should hold your speed value!)

$(this).hide(parseInt($("#hide_speed").val(),10));

<https://developer.mozilla.org/en/Java/Reference/Global_Objects/parseInt”rel=“nofollow>parseInt(>用于确保投入的价值确实是数量。 该职能接受2项论点,价值本身,以及反省价值(10项数字,2项为二元,16项为六种)。

还可使用<代码><select>和其他种类的投入。

问题回答

1. 通过阀级功能确定身份识别器的甄选和使用元件

    <script>
      $(document).ready(function () {
        $("#pid1").click(function () {
            $(this).hide(parseInt($("#youtextinput").val(),10));
        });
    });
    </script>

    <body>
    <p id = "pid1">This is paragraph</p>
    <input type="text" id="youtextinput"/>
    </body>

你的问题非常模糊......但这里是......使用户能够选择超文本的速率:

<select id="UserSelectedSpeed">
  <option value="slow">Slow</option>
  <option value="fast">Fast</option>
</select>

之后:

$(document).ready(function () {
    $("#pid1").click(function () {
        $(this).hide($( #UserSelectedSpeed ).val());
    });
});

<代码>(美元) #UserS selectedSpeed .val( >从<条码>上获得目前选定的数值。

Working example here





相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Elegant way building url request with parameters

There must me a more elegant way to build a URL with parameters in .NET then for example Response.Write("<a href=HeadOfMarketView.aspx"+Session["HOM"] != null ? Session["HOM"]+">Head of Market&...

Can you pass by reference in Java?

Sorry if this sounds like a newbie question, but the other day a Java developer mentioned about passing a paramter by reference (by which it was ment just pass a Reference object) From a C# ...

How to name a method that has an out parameter?

What is the common preference to name a method that has an out parameter inside? Usually I use Get as a prefix to mention that the method returns a value (like GetMyBusiness). But what if there is ...

How to create program startup parameters in python

I m just beginning to learn python and the program I m writing requires parameters for it to run with a specific task. For example (programs name is Samtho) samtho -i Mozilla_Firefox How can I do ...

Weird behaviour of h:commandLink action (MethodExpression)

I have two JSPs where I am displaying some info from database in a h:dataTable. One of them is showing all the info, and one of them user specifically. I have showXML.jsp that shows the "XML" column ...

using parameter in SQL with LIKE keyword

from my C#-programm, I access a SQL Server 2008 Database. I have a table with a fulltextindex and want to search for an indexed entry: SELECT page_id FROM page_categories WHERE page_title LIKE @title ...

采用网路服务方法

我撰写了一个网络服务,期望一个参数(所谓的“hlink”)成为一种ur。 在使用网络服务之前,URLEncode 所涉参数(“hlink”)。 然后我打电话......。

热门标签