GVKun编程网logo

如何通过仅给出其ID获得元素的所有应用样式?(根据id获取元素)

16

这篇文章主要围绕如何通过仅给出其ID获得元素的所有应用样式?和根据id获取元素展开,旨在为您提供一份详细的参考资料。我们将全面介绍如何通过仅给出其ID获得元素的所有应用样式?的优缺点,解答根据id获取

这篇文章主要围绕如何通过仅给出其ID获得元素的所有应用样式?根据id获取元素展开,旨在为您提供一份详细的参考资料。我们将全面介绍如何通过仅给出其ID获得元素的所有应用样式?的优缺点,解答根据id获取元素的相关问题,同时也会为您带来@nuxtjs/vuetify 没有应用样式、Android获取所有应用的资源id和对应的uri、Android获得当前安装的所有应用程序列表、Android获得当前设备支持的所有传感器的实用方法。

本文目录一览:

如何通过仅给出其ID获得元素的所有应用样式?(根据id获取元素)

如何通过仅给出其ID获得元素的所有应用样式?(根据id获取元素)

我试图编写一个函数,该函数接受元素的ID并给出应用于该元素的所有样式属性(及其值)的列表。它应该考虑内联样式以及css文件中定义的样式。

当我在参数中提供样式属性名称以及元素的ID时,我可以使函数起作用,但是我只想传递元素的ID,并且应该能够获取所有样式属性以及值。

函数应该类似于getStyleById(elementId);

到目前为止,PFB的代码片段:

var styleNode = [];    var styles;    var sty = x.style;    var len = sty.length;    for (var i = 0; i < len; i++) {        styles = sty.item(i);        if (x.currentStyle)     //IE for External/Global Styles        {            var a = x.currentStyle[styles];            styleNode.push(styles + ":" + a);        }        else if (document.defaultView && document.defaultView.getComputedStyle)    //Firefox,Chrome,Safari for External/Global Styles        {            var b = document.defaultView.getComputedStyle(x, "").getPropertyValue(styles);            styleNode.push(styles + ":" + b);        }        else           //Works in Inline Styles only        {            var c = x.style[styles];            styleNode.push(styles + ":" + c);        }    }

任何帮助,将不胜感激。

问候,

Manishekhawat

答案1

小编典典

使用以下方法:

  • 遍历CSSStyleDeclaration对象的索引(getComputedStyle)以获取每个已知的属性名称。使用getPropertyValue+这个名称来获取值。
    代码优化:不要getComputedStyle用于每次迭代,而是将其存储在循环外部的变量中。

  • 对使用普通for ( name in object )循环currentStyle

  • 对内联样式使用相同的循环方法

码:

function getStyleById(id) {    return getAllStyles(document.getElementById(id));}function getAllStyles(elem) {    if (!elem) return []; // Element does not exist, empty list.    var win = document.defaultView || window, style, styleNode = [];    if (win.getComputedStyle) { /* Modern browsers */        style = win.getComputedStyle(elem, '''');        for (var i=0; i<style.length; i++) {            styleNode.push( style[i] + '':'' + style.getPropertyValue(style[i]) );            //               ^name ^           ^ value ^        }    } else if (elem.currentStyle) { /* IE */        style = elem.currentStyle;        for (var name in style) {            styleNode.push( name + '':'' + style[name] );        }    } else { /* Ancient browser..*/        style = elem.style;        for (var i=0; i<style.length; i++) {            styleNode.push( style[i] + '':'' + style[style[i]] );        }    }    return styleNode;}

@nuxtjs/vuetify 没有应用样式

@nuxtjs/vuetify 没有应用样式

如何解决@nuxtjs/vuetify 没有应用样式?

我在 Nuxt 项目中使用 vuetify 时遇到问题,我已经按照文档说您只需要将 @nuxtjs/vuetify 依赖项安装到您的项目并在您的项目的 buildModules 部分添加一行nuxt.config.js 文件。组件工作正常,但我没有看到任何 css 样式,怎么了?

nuxt vuetify no css

这是我的 nuxt.config.js 文件

   export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: ''mounir-ssr-diabete'',htmlAttrs: {
      lang: ''en'',},Meta: [
      { charset: ''utf-8'' },{ name: ''viewport'',content: ''width=device-width,initial-scale=1'' },{ hid: ''description'',name: ''description'',content: '''' },],link: [{ rel: ''icon'',type: ''image/x-icon'',href: ''/favicon.ico'' }],// Global CSS: https://go.nuxtjs.dev/config-css
  css: [],// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  plugins: [],// Auto import components: https://go.nuxtjs.dev/config-components
  components: true,// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [
    // https://go.nuxtjs.dev/typescript
    ''@nuxt/typescript-build'',[''@nuxtjs/vuetify'',{}],router: {},// Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    // https://go.nuxtjs.dev/axios
    ''@nuxtjs/axios'',[
      ''@nuxtjs/firebase'',{
        config: {
          apiKey: ''AIzaSyD_wgrl3S3RjpgwaEP2bDLpLDnIQz2C2Vc'',authDomain: ''mounir-ssr.firebaseapp.com'',projectId: ''mounir-ssr'',storageBucket: ''mounir-ssr.appspot.com'',messagingSenderId: ''26338888590'',appId: ''1:26338888590:web:be1893a374f3abc10cb2df'',measurementId: ''G-Y7YHDQDLM8'',services: {
          auth: {
            persistence: ''local'',// default
            initialize: {
              onAuthStateChangedAction: ''onAuthStateChangedAction'',subscribeManually: false,ssr: false,// Axios module configuration: https://go.nuxtjs.dev/config-axios
  axios: {},// Build Configuration: https://go.nuxtjs.dev/config-build
  build: {},}

解决方法

您应该在 vuetify 文件中与 nuxt.config.jsaxios 一起添加 build 主题信息。像这样..

  buildModules: [
    // Doc: https://github.com/nuxt-community/eslint-module
    "@nuxtjs/eslint-module","@nuxtjs/vuetify",],/*
   ** Nuxt.js modules
   */
  modules: [
    // Doc: https://axios.nuxtjs.org/usage
    "@nuxtjs/axios",/*
   ** Axios module configuration
   ** See https://axios.nuxtjs.org/options
   */
  axios: {},vuetify: {
    customVariables: ["~/assets/variables.scss"],theme: {
      light: true,themes: {
        dark: {
          primary: colors.blue.darken2,accent: colors.grey.darken3,secondary: colors.amber.darken3,info: colors.teal.lighten1,warning: colors.amber.base,error: colors.deepOrange.accent4,success: colors.green.accent3,},

问我是否不清楚。

Android获取所有应用的资源id和对应的uri

Android获取所有应用的资源id和对应的uri

背景

在某些应用中,为了实现应用apk资源放入重复利用,或者使用反射得到本应用的资源,需要使用反射方式获得,但Resources类中也自带了这种获取方式,并且功能更加强大

你可以获取string,color,drawable,raw,xml等文件,因此也就意味着,这里可以获取的资源是res中已定义的资源,对于控件id的获取,暂时无法做到

public int getIdentifier(String name, String defType, String defPackage) {
    if (name == null) {
        throw new NullPointerException("name is null");
    }
    try {
        return Integer.parseInt(name);
    } catch (Exception e) {
        // Ignore
    }
    return mAssets.getResourceIdentifier(name, defType, defPackage);
}

获取资源的Id

    获取当前应用的资源Id

int drawableId = mContext.getResources().getIdentifier("ic_launcher","drawable", mContext.getPackageName());
mImageView.setImageResource(drawableId);

    获取其他应用的资源Id

int id = mContext.getResources().getIdentifier("icon", "drawable", "com.android.testproject");
// 或者
int id = mContext.getResources().getIdentifier("com.android.testproject:drawable/icon", null, null);

    整合到一起

public static int getResourceId(Context context, String name, String type, String packageName){
    Resources themeResources=null;
    PackageManager pm=context.getPackageManager();
    try {
        themeResources=pm.getResourcesForApplication(packageName);
        return themeResources.getIdentifier(name, type, packageName);
    } catch (NameNotFoundException e) {

        e.printStackTrace();
    }
    return 0;
}

获取系统资源Id

int id = getResources().getIdentifier("actionbar_bg", "drawable","android");  //注意,最后一个参数必须是“android”

获取资源的Uri

android系统中,应用的资源存储时也通常会被存入 数据库,也可以被共享,
因此来说资源也可以获得uri

public static  Uri getResourceUri(int resId,String packageName) {
    return Uri.parse("android.resource://"+packageName+"/"+resId);
}

 

Android获得当前安装的所有应用程序列表

Android获得当前安装的所有应用程序列表

下面是小编 jb51.cc 通过网络收集整理的代码片段。

小编小编现在分享给大家,也给大家做个参考。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    lView = (ListView) findViewById(R.id.list1);

    PackageManager pm = this.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN,null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    List list = pm.queryIntentActivities(intent,PackageManager.PERMISSION_GRANTED);

    for (ResolveInfo rInfo : list) {
        results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
        Log.w("Installed Applications",rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
    }

    lView.setAdapter(new ArrayAdapter(this,android.R.layout.simple_ list_item_1,results));
}

以上是小编(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给程序员好友。

Android获得当前设备支持的所有传感器

Android获得当前设备支持的所有传感器

package zhangphil.sensor;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private SensorManager mSensorManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        startSensor();
    }

    private void startSensor() {
        mSensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);

        if (mSensorManager == null) {
            throw new UnsupportedOperationException();
        }

        List<Sensor> sensorsList = mSensorManager.getSensorList(Sensor.TYPE_ALL);
        for (Sensor sensor : sensorsList) {
            Log.d("支持的传感器", sensor.getName().toString());
        }
    }
}

今天关于如何通过仅给出其ID获得元素的所有应用样式?根据id获取元素的介绍到此结束,谢谢您的阅读,有关@nuxtjs/vuetify 没有应用样式、Android获取所有应用的资源id和对应的uri、Android获得当前安装的所有应用程序列表、Android获得当前设备支持的所有传感器等更多相关知识的信息可以在本站进行查询。

本文标签: