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

javascript - Make contents in div not editable (clickable) - Stack Overflow

programmeradmin6浏览0评论

I don't know if this is possible or not.

I have a dynamic form with contents that are dynamically created. Every time a button is clicked, a new div element is added. And what I wanted to do is to make the previous div not editable, that is, the input fields could not be used, buttons could not be clicked.

Is it doable?

Thanks.

I don't know if this is possible or not.

I have a dynamic form with contents that are dynamically created. Every time a button is clicked, a new div element is added. And what I wanted to do is to make the previous div not editable, that is, the input fields could not be used, buttons could not be clicked.

Is it doable?

Thanks.

Share Improve this question edited Sep 19, 2012 at 8:04 Jasper de Vries 20.3k6 gold badges67 silver badges107 bronze badges asked Sep 19, 2012 at 7:56 Severino Lorilla Jr.Severino Lorilla Jr. 1,6374 gold badges20 silver badges34 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 4

Try something like this:

// Disable all input-like elements in the divs except for the last div
$(".divclass:not(:last-child) :input").attr("disabled", true);

Where divclass is the class of the divs you mentioned.

Example: http://jsfiddle/grc4/LrxkU/2/

Maby something like this? http://jsfiddle/ng4Ct/2/

If you can access your previous div elements you can add attribute disabled="disabled" to them.

You can fire the code that adds the disabled attribute to required elements on the same button click function.

Well, you can either access the specific elements inside the DIV and disable them using Javascript, or you can access the DIV and then loop through all the elements inside (probably preferable), and disable them automatically with Javascript.

Of course it depends on how your code is written, can you provide some of the code that generates the DIVs?

发布评论

评论列表(0)

  1. 暂无评论