English 中文(简体)
从组合框中获取值并向其添加一个数字
原标题:Get value from combobox and add a number to it
  • 时间:2012-05-27 15:58:22
  •  标签:
  • javascript

我试图从组合框中获取“值”,并简单地向其中添加一个。我认为我需要将其转换为整数,但也无法使解析工作。接下来,我想把这个新数字放进一个文本框里。

<script type="text/javascript">
    function GetNextCategoryNum(sel)
    {
        var NextNumber; 
        var number = sel.options[sel.selectedIndex].value; 
        NextNumber = number ++1;
        alert("Last number used "  + number );
        textbox = NextNumber 
    }
</script>
问题回答

Three mistakes in your code:
1. value will return a string. So you need to change it to an integer.
2. "number ++1" is wierd. What you need is ++number. If you do not want to increase "number" but "NextNumber", then just put on number + 1.
3. What is "textbox"? if it refers to a textbox object then you need declaring it.

所以我的建议是:

<script type="text/javascript">
    function GetNextCategoryNum(sel)
    {
        var NextNumber; 
        var textbox = document.getElementById("textbox");
        var number = parseInt(sel.options[sel.selectedIndex].value); 
        NextNumber = number + 1;
        alert("Last number used "  + number );
        textbox.value = NextNumber;
    }
</script>




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签