dothis dothat功能不起作用

时间:2016-08-04 12:31:35

标签: javascript

我有两个相似的脚本,但只有一个在页面内部工作,但工作分别很好。我希望在我阅读http://www.javascriptkit.com/javatutors/eventaction4.shtml

的页面内进行操作时没有任何问题

我试过这样做,但是没有人有任何想法吗?



function dothis(){
var z = 1; //value to make div overlappable

$('#addText').click(function (e) {
    /** Make div draggable **/
    $('<div />', {
        class: 'ui-widget-content',
        appendTo: '.container4',
        draggable: {
            containment: 'parent',
            start: function( event, ui ) {
                $(this).css('z-index', ++z);
            }
        }
    });
});


$(document).on("dblclick", '.text1', function()
{
    $(this).hide();    $(this).closest('.item1').find('.edit_text1').val($(this).text()).show();
});

$(document).on("click", ".edit_text1", function()
{
    return false;
});


$(document).on("click", function()
{
    var editingText = $('.edit_text1:visible');
    if (editingText.length)
    {
        editingText.hide();
        editingText.closest('.item1').find('.text1').text($(editingText).val()).show();
    }
});


    var count = 1;
var selectedDraggable;

ko.bindingHandlers.draggable={
    init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
        $(element).draggable();
        $(element).addClass('item1' + count);
        count++;
        $(element).on('click', function () {
            selectedDraggable = $(this);
        })
    }
};


var vm=function(){
    var self=this;
    self.items1=ko.observableArray();
    self.textContent1 = ko.observable('');
    self.init=function(){
        self.items1([]);
    }
    self.remove=function(item){
        console.log(item);
        self.items1.remove(item);
    }
    self.addNew1 = function() {
      self.items1.push( self.textContent1() );
      self.textContent1('');
    }
    self.init();
}

ko.applyBindings(new vm());



$("#fss").change(function() {
    selectedDraggable.css("font-family", $(this).val());
});



$("#size1").change(function() {
    selectedDraggable.css("font-size", $(this).val() + "px");
});


$('.fooo').click(function(){
    selectedDraggable.css("color", $(this).attr('data-color'));
});

$(document).ready(function(){
    $("#rotateButton1").click(function(){
       var x= $("#rotateInput").val();      
     selectedDraggable.css('transform','rotate(' + x + 'deg)');
      
    });
});
}
  
 function dothat(){
var z = 1; //value to make div overlappable

$('#addText').click(function (e) {
    /** Make div draggable **/
    $('<div />', {
        class: 'ui-widget-content',
        appendTo: '.container',
        draggable: {
            containment: 'parent',
            start: function( event, ui ) {
                $(this).css('z-index', ++z);
            }
        }
    });
});


$(document).on("dblclick", '.text', function()
{
    $(this).hide();    $(this).closest('.item').find('.edit_text').val($(this).text()).show();
});

$(document).on("click", ".edit_text", function()
{
    return false;
});


$(document).on("click", function()
{
    var editingText = $('.edit_text:visible');
    if (editingText.length)
    {
        editingText.hide();
        editingText.closest('.item').find('.text').text($(editingText).val()).show();
    }
});


    var count = 1;
var selectedDraggable;

ko.bindingHandlers.draggable={
    init: function(element, valueAccessor, allBindingsAccessor, viewModel) {
        $(element).draggable();
        $(element).addClass('item' + count);
        count++;
        $(element).on('click', function () {
            selectedDraggable = $(this);
        })
    }
};


var vm=function(){
    var self=this;
    self.items=ko.observableArray();
    self.textContent = ko.observable('');
    self.init=function(){
        self.items([]);
    }
    self.remove=function(item){
        console.log(item);
        self.items.remove(item);
    }
    self.addNew = function() {
      self.items.push( self.textContent() );
      self.textContent('');
    }
    self.init();
}

ko.applyBindings(new vm());



$("#fs").change(function() {
    selectedDraggable.css("font-family", $(this).val());
});



$("#size").change(function() {
    selectedDraggable.css("font-size", $(this).val() + "px");
});


$('.foo').click(function(){
    selectedDraggable.css("color", $(this).attr('data-color'));
});

$(document).ready(function(){
    $("#rotateButton").click(function(){
       var x= $("#rotateInput").val();      
     selectedDraggable.css('transform','rotate(' + x + 'deg)');
      
    });
});
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body onload="dothis();dothat()">​
&#13;
&#13;
&#13;

0 个答案:

没有答案