English 中文(简体)
使用模板时如何在 div 上添加拖动功能
原标题:how to add draggable functionality on a div when using a template

我想在运行时在 div 上添加可拖动功能。 div s id 是通过以下代码生成的 :

var Exp=0;
view.renderFunction = function(id1){
  var id= id1 + Exp++;
  $("#"+id).draggable();
};

This is my function where the id is dynamically generated when I drop div. But when I apply the draggable method it can t move. How can I move div?

最佳回答

我用动能.j.js,现在工作正常

问题回答

它会工作,已经测试了这一点。

确保以下各点:

  • Make sure you know what is Exp++ (you haven t mentioned about it in the question)
  • The element on which you call draggable() is a valid DOM element.
  • Try calling it on document ready or DOM ready

以下为工作小提琴:http://jsfiddle.net/gopi1410/ByWCS/

Are you facing trouble with dragging itself or is the problem only with dropping it anywhere? This should be pretty straight forward. Here is a sample that shows dragging a child div from one parent div to another: How to enable dragging a div from one parent div to another

var id= id1 + Exp++; 
$("#"+id).draggable(); 

Exp/code> 是什么, 您是否确定您正在对现有元素调用 . drggable () ? 另外, 您是否曾经使用 id 来调用此功能?





相关问题
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.