最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make a textbox clickable - Stack Overflow

programmeradmin7浏览0评论

can anyone help how to make a textbox clickable while it is a in readonly state.

I want to do is a can click my textboxes just like a button because i have plans to it.

<input type="text" readonly value="Click me" id="clickme" />

can anyone help how to make a textbox clickable while it is a in readonly state.

I want to do is a can click my textboxes just like a button because i have plans to it.

<input type="text" readonly value="Click me" id="clickme" />
Share Improve this question asked Mar 19, 2014 at 7:36 user3424886user3424886 593 silver badges9 bronze badges 2
  • is always in readonly mode? – user3401335 Commented Mar 19, 2014 at 7:40
  • If you want to do things with it why are you setting readonly in the first place? – David Thomas Commented Mar 19, 2014 at 7:41
Add a ment  | 

9 Answers 9

Reset to default 1

Like this, readonly catch click, disabled doesen't . fiddle

$(function(){
    $('#clickme').on('click', function(){
        alert(1)
    })    
})
<input type="text" readonly value="Click me" id="clickme" onClick="myFunction()"/>


<script>
    ...
    function myFunction(){
        // Your function
    }
    ...
</script>

Just add a click event to the textbox.

JQuery:

$("#clickme").click(function(){
alert("do something");
});

JsFiddle

Jquery is awesome if you include it.

$('#clickme').on('click', function(e) {
   // do something 
});

Without more information as to what, precisely, you want to do, I'd suggest:

$('#clickme').on('click', function(){
    // to allow for editing of contents:
    $(this).prop('readonly', false);
});

JS Fiddle demo.

Or:

$('#clickme').on('click', function(){
    // to do something if this is readonly:
    if (this.readOnly) {
        // for example:
        console.log('this input is readonly');
    }
});

JS Fiddle demo.

You can use jquery as

$('#clickme').click(function(){
 alert('clickable');
// Your Method.
});

Add few style too

#clickme
{
cursor:pointer;
cursor:hand;
}

Check out this Demo

you can use onclick function, like

    <input type="text" readonly value="Click me" id="clickme" onclick="myfunction()" />
$('#clickme').click(function(){
  alert('Textbox is clicked)
});

You can use:

$('#clickme').click(function(){
  // logic here
});
发布评论

评论列表(0)

  1. 暂无评论