如何让我的convertFunction()将转换后的数据放入“输入行”? [英] How do I get my convertFunction() to put the converted data in the 'input line' ?

查看:86
本文介绍了如何让我的convertFunction()将转换后的数据放入“输入行”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须道歉,我是新来的,对不起,如果我的格式错了。

我想要的是让我的convertFnction(con1)将转换后的数据放回到

用户提交的输入行。



想法是让用户键入5个数字,并将convertFunction()返回值作为转换值放入输入行。然后'提交'它。

附注:似乎将数字传递给函数有时会出现问题,

不知道为什么。



I must apologize, am new here, sorry if my format is wrong.
What I would like is to have my convertFnction(con1) put the converted data back into
the input line where it will be submitted by user.

The idea is to have the user type in 5 numbers and the convertFunction() return value will be put in the 'input line' as the converted value. Then 'submit' it.
A side note: It seems that passing in the number to the function is sometimes problematic,
not sure why.

<pre lang="text"><pre lang="HTML"><pre lang="CSS"><pre lang="Javascript">

<pre lang="Javascript">

<pre lang="CSS"><pre lang="Javascript"><pre lang="xml"><form method="get" action="forms_wifi.html">
    <td>Convert_test:</td>
    <td><input type="text" size=31 name="Con1" value="Con1"  onclick="convertFunction('Con1')"> </td>
    <td><input type="submit"  value="Submit" > </td> <!-- '54321' works  -->
    </form>





< script type =text / javascript>





<script type="text/javascript">

    function convertFunction(convalue)
    {
        var con1 = convalue;
        var m = "54321";
        var n = con1.localeCompare(m);

        if(n == 0)          /* var n = str1.localeCompare(str2); 95673 */
        {
            value = "good";   // put value in input line.
            alert("95673");   // debug alert
            return "95673";
        }
        else
        {
            value = "nogood";  // value of input line.
            alert("nogood");
            return "nogood";
        }
    }
</script>

推荐答案

你的目的和 onclick 处理程序的目的( convertFunction )对我来说还不清楚;一切看起来很奇怪。但是有一个问题很明显:你抱怨将数据传递给函数,而是传递一些字符串常量,Con1。那么你会期待什么?



无论你想做什么,都需要传递一些与文本输入控件相关的变量。最通用的方法是通过它的引用this。请查看此示例的工作原理:

You purpose and the purpose of the onclick handler (convertFunction) remain unclear to me; all looks weird. But one problem is apparent: you complain about passing data to a function, but instead pass some string constant, "Con1". What would you expect then?

Whatever you want to do, you need to pass some variable related to the text input control. Most general way is to pass its reference, "this". Please see how this sample works:
<html>

   <head>
      <script>
         function onTextClick(data) {
            alert(data.value);
         }			
      </script>
   </head>

<body>
   <input type="text" value="some text value" onclick="onTextClick(this)">
</body>

</html>





在此示例中, alert 调用将使用此处理程序显示输入元素中输入的文本。在您的真实处理程序中,您可以根据需要使用此数据。即使这是奇怪的事情。 :-)



-SA



In this sample alert call will show the text entered in the input element using this handler. In your "real" handler, you can do with this data whatever you want. Even if this is something weird. :-)

—SA


谢尔盖,

我点击绿色按钮接受解决方案但没有任何反应.....

除了按钮现在显示'拒绝'。

我不想拒绝。我做错了什么?



我很快就会有更多问题。



亲切的,
Jim
Sergey,
I clicked the green button to accept the solution but nothing happened.....
Except that the button now says 'Reject'.
And I do not want to Reject. Did I do something wrong?

I will have more questions soon.

Kindly,
Jim


这篇关于如何让我的convertFunction()将转换后的数据放入“输入行”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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