我正在尝试优化一些代码,因此可以动态地使其从网站上获取HTML内容。 因此,我得到了以下代码,并希望有时使用.innerHTML有时用.href代替,同时将.innerHTML保留为默认值。
function copySourceToDestination(the_source, the_destination) {
var featureSource = document.querySelector(the_source).innerHTML;
var featureDestination = document.querySelector(the_destination);
featureDestination.innerHTML = featureSource;
}
但是,如果我尝试此操作无效:
function copySourceToDestination(the_source, the_destination, the_selector = 'innerHTML') {
var featureSource = document.querySelector(the_source).the_selector;
var featureDestination = document.querySelector(the_destination);
featureDestination.the_selector = featureSource;
}