2011-09-14 48 views
0

As the title says I'm trying to basically added the numbers 0-9 to a text box and also be able to delete the last input number(basically last digit in textbox or decrease length of data by 1 or w/e to produce this).如何值.append使用<a onclick and then also delete last value added (values = 0-9)

Like you can see below I've setup basically a keypad of buttons which I'm trying to record the value of each to a specific textbox.

<%: Html.TextBox("TBBlah") %> 

<a onclick="$('#TBBlah').append('7');" class="large button" style="color:Black; text-decoration:none;">7</a> 
    &nbsp; 
    <a onclick="$('#TBBlah').append('8');" class="large button" style="color:Black; text-decoration:none;">8</a> 
    &nbsp; 
    <a onclick="$('#TBBlah').append('9');" class="large button" style="color:Black; text-decoration:none;">9</a> 

I'm trying to set this up in this precise way to allow users to enter a code via a touchscreen.

With the code above it says Object doesn't support this property or method which has me wondering what I did wrong.

also was wondering in case this would help (these are in my site.master file)

<!-- jQuery --> 
    <script src="<%= Url.Content("~/scripts/jquery-1.6.2.js") %>" type="text/javascript"></script> 
    <script src="<%= Url.Content("~/scripts/jquery-1.6.2.min.js") %>" type="text/javascript"></script> 
    <!-- /jQuery--> 

    <!-- jQuery UI --> 
    <script src="<%= Url.Content("~/content/script/jquery-ui-1.8.16.custom.min.js") %>" type="text/javascript"></script> 
    <link href="<%= Url.Content("~/content/css/cupertino/jquery-ui-1.8.16.custom.css") %>" rel="stylesheet" type="text/css" media="screen" /> 
    <!-- /jQuery UI --> 

I hope I haven't missed out anything but if I have ask and I shall provide.

+0

快一点,你不需要两个jQuery的脚本。你只需要一个。没有min的是未压缩的代码或者开发代码,min是压缩代码。 – NebulaFox

+0

现在删除了最小版本,但任何想法,我会如何去删除一个数字,我会添加1? (通过这个,我只是表示希望它会在onclick事件中) – Myzifer

回答

1

append can't be used in your case since it will append something to the text inside some element, whereas in your case you are adding text into textbox which should use text property to access its content.

CORRECTED VERSION:

onclick= "$('#TBBlah').val($('#TBBlah').val() + $(this).text())" ; 

This will append the newly clicked number to the value inside textbox.

+1

我不太明白这是如何工作的。由于表面上你得到'#TBBlah'的'text'并将其添加到'this'的'text',由于字符串是不可变的,它不会改变'#TBBlah'的结果。 – NebulaFox

+1

而'text'和'append'一样。它在标签之间放置文本,或者在标签之间获取文本。 – NebulaFox

+0

我刚刚完成了试用无效代码和许多不同的方式来使用此代码,没有任何工作。 对于初学者来说,它似乎并没有指出你将文本的值赋给文本框的位置,所以我试图把它放到$(this).text()中。例如'9'和9。因为我现在已经注意到你提出了我的改正版本,我会试着看看我是否可以让它工作,并看看nebulafox的解决方案。 – Myzifer

0

It help to find out what HTML.TextBox actually created was an input field. You don't want to append, wich adds stuff between two tags you want to add the to the input value. So

onclick="$('#TBBlah').val('7');" 

Here's a link for you: http://api.jquery.com/val

一个文本框和用于道路Ghazanfar米尔做到了

onclick="$('#TBBlah').val($(this).text());" 
相关问题