我有网站应用程序和java应用程序。 Java用户在页面上有其他按钮,所以我需要在移动菜单和正常大小的菜单上添加一个按钮。这就是我的java代码工作方式
...
String javascript = "javascript:"
+ "$(document).ready(function() {"
+ "function foobar1() {Android.foobar1();}"
+ "function foobar2() {Android.foobar2();}"
+ "function foobar3() {Android.foobar3();}"
+ "function foobar4() {Android.foobar4();}"
+ "var foobar1 = document.createElement('div');"
+ "var foobar2 = document.createElement('div');"
+ "var foobar3 = document.createElement('div');"
+ "var foobar4 = document.createElement('div');"
+ "foobar1.className = 'profilebuttons';"
+ "foobar2.className = 'profilebuttons';"
+ "foobar3.className = 'profilebuttons';"
+ "foobar4.className = 'profilebuttons';"
+ "foobar1.innerHTML = 'foobar';"
+ "foobar2.innerHTML = 'foobar';"
+ "foobar3.innerHTML = 'foobar';"
+ "foobar4.innerHTML = 'foobar';"
+ "foobar1.onclick = foobar1;"
+ "foobar2.onclick = foobar2;"
+ "foobar3.onclick = foobar3;"
+ "foobar4.onclick = foobar4;"
+ "element = document.getElementsByClassName('contentMenu')[0];"
+ "element.appendChild(foobar1);"
+ "element.appendChild(foobar2);"
+ "element.appendChild(foobar3);"
+ "element.appendChild(foobar4);"
+ "});";
view.loadUrl(javascript);
...
这是我的jquery代码
$(document).ready(function() {
var $products = $(".profilebuttons"),
$contentMenu = $(".contentMenu"),
$profileButtons = $('#profileButtons'),
transferProduct = $(".transferProduct"),
products = $(".products"),
productCategorys = $(".productCategorys");
$products.click(function () {
$profileButtons.find('.profileButtonsCollection').hide();
$profileButtons.find('.mobileButton').hide();
$profileButtons.css('display','flex');
$.each($contentMenu.children(), function (index) {
if (index === 0) {} else {
var $cloned = $(this).clone(true,true);
$(this).removeClass('profilebuttons').appendTo($profileButtons.find('.profileButtonsCollection'));
$cloned.removeClass('profilebuttons').appendTo($profileButtons.find('#websiteUrls').find('.menu'));
}
});
...
在jquery示例中第一个工作。我不明白如何使用java代码中的函数克隆对象,它们附加在2个菜单中。