admin管理员组

文章数量:1416074

Thanks once again,for all great mind's.

My expectation is exactly what the they have in example site.

example site:

--->creating text box dynamically onclick in CANVAS area only.

--->text box input text's font,font size,color .. changed by getting id var somename = document.getelementbyid("id of textbox -in this case id getting uniquely"); somename = here all function for changing color, font are follows

but,

my problem is to add text box dynamically onclick button,so how to assing id for var somename = document.getelementbyid("id of textbox(dynamically created text box id)");

At the same time that text box should be movable any were in canvas.

Thanks once again,for all great mind's.

My expectation is exactly what the they have in example site.

example site: http://www.printvenue./customer-design/editor/rounded-corner-business-cards/3-0128-vc-psd

--->creating text box dynamically onclick in CANVAS area only.

--->text box input text's font,font size,color .. changed by getting id var somename = document.getelementbyid("id of textbox -in this case id getting uniquely"); somename = here all function for changing color, font are follows

but,

my problem is to add text box dynamically onclick button,so how to assing id for var somename = document.getelementbyid("id of textbox(dynamically created text box id)");

At the same time that text box should be movable any were in canvas.

Share Improve this question edited Feb 19, 2014 at 11:17 user3304886 asked Feb 18, 2014 at 18:25 user3304886user3304886 11 gold badge1 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

You can create a new HTML element like this:

var textBox = document.createElement("textarea");

To add it to the parent use

document.getElementById([insert id of parent here]).appendChild(textBox);

This parent should be the div/html-element in which all the textareas are located.

Example in JSFiddle

HTML

<div id='parent'>
    <textarea>txt1</textarea>
    <textarea>txt2</textarea>
    <textarea>txt3</textarea>
</div>
<button onClick="addBox()">add textarea</button>

JS

addBox = function(){
    var textBox = document.createElement("textarea");
    document.getElementById("parent").appendChild(textBox);
}

Example in JSFiddle with JQuery

HTML

<div id='parent'>
    <textarea>txt1</textarea>
    <textarea>txt2</textarea>
    <textarea>txt3</textarea>
</div>
<button>add textarea</button>

jQuery

$(function(){
    $('button').on('click', function(){
        var textBox = document.createElement("textarea");
        $('#parent').append(textBox);
    });
});

Here the link that you wanted :

JavaScript Version:

HTML

<input id='inp' type='button' value='Click me'/>
<div id='cont'>

</div>

JavaScript

document.getElementById('inp').addEventListener('click', function () {
        var textarea = document.createElement('textarea');
        textarea.className="mytextbox";
        document.getElementById('cont').appendChild(textarea);
    });

Css

.mytextbox{
    width:200px;height:200px;box-shadow:2px 1px 5px 1px #000;

}

jQuery Version :

HTML

<input id='inp' type='button' value='Click me'/>
<div id='cont'>

</div>

jQuery

$('input').click(function(){

     var textarea =  $('<textarea></textarea>');
     textarea.css({'width':'200px','height':'200px','box-shadow':'1px 2px 5px 1px #000'});
    $('#cont').append(textarea);

});

本文标签: