使用特定坐标创建div

时间:2015-05-19 08:31:00

标签: javascript jquery html css jquery-ui

HTML:

<div id="textDiv">
    <input type="text" id="txt" value="Add TextBox" style="" readonly /><br>
</div>
<div id="holder"></div>

有2 div。使用jQuery UI,divdiv创建了一个新的id="holder"

在剧本中:

$(document).ready(function () {
    $("#textDiv").draggable({
        helper: 'clone',
    });
    $("#holder").droppable({
        drop: function (event, ui) {
            var newTextBoxDiv = $(document.createElement('div')).attr("id", 'Div' + inputs.length);
            newTextBoxDiv.after().html(
                '<label id="textLabel' + inputs.length + '">TextboxLabel #' + i + ' : </label>
                <input type="text" name="textbox' + inputs.length + '" id="text' + inputs.length + '" value="" placeholder="textbox #' + i + '" checked="" >
                <input type="button" onclick="xtext(\'' + inputs.length + '\')" id="xtext' + inputs.length + '" value="x">
                <input type="button" onclick="edittext(\'' + inputs.length + '\')"  id="edittext' + inputs.length + '" value="edit">');
                newTextBoxDiv.appendTo("#holder");
            i++;
        }

如何在删除克隆时插入鼠标停止的新div

1 个答案:

答案 0 :(得分:1)

您可以像这样在X轴和Y轴上转换div中心 -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.webception.demoappview.MainActivity$PlaceholderFragment" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

</RelativeLayout>

或使用JavaScript:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.webception.demoappview"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
       <activity
            android:name="com.example.androidwebviewexample.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

<activity 
        android:name="com.example.androidwebviewexample.WebActivity">
    </activity>

    </application>

</manifest>